﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BAL;
using Common;

namespace Web
{
    public partial class PostArea : System.Web.UI.Page
    {
        private int editid = 0;
        private int delid = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserValidate.CheckLogin(this.Request, "MasterSchool"))
            {
                Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                Response.Redirect("login.aspx");
                Response.End();
            }

            if (Request.QueryString["editid"] != null)
            {
                editid = Convert.ToInt32(Request.QueryString["editid"].Trim());
            }
            if (Request.QueryString["delid"] != null)
            {
                delid = Convert.ToInt32(Request.QueryString["delid"].Trim());
            }
            if (!IsPostBack)
            {
                if (editid > 0)
                {
                    AreaInfo areaInfo = new AreaInfo();
                    areaInfo = Area.GetSingleInfo(editid);
                    AreaName.Text = areaInfo.Name.ToString();
                }
                if (delid > 0)
                {
                    if (!UserValidate.CheckLogin(this.Request, "DelSchool"))
                    {
                        Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                        Response.Redirect("login.aspx");
                        Response.End();
                    }
                    Area.DelInfo(delid);
                    Response.Redirect("AdminSchool.aspx");
                    return;
                }

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (AreaName.Text.Trim() == "")
            {
                Utility.ShowJsAlert("区域名称不能为空", this);
                return;
            }
            AreaInfo areaInfo = new AreaInfo();
            areaInfo.Name = AreaName.Text.Trim();
            if (editid > 0)
            {
                areaInfo.Id = editid;
            }
            Area.Save(areaInfo);
            Utility.ReloadTopPage(this);
        }
    }
}
